/* Copyright © Worklight Ltd. 2006-2011.  All rights reserved. */

package com.worklight.wlclient.api;

import java.util.HashMap;
import java.util.Map;


/**
 * This class used to pass data all the way
 * User can add his object with the setInvokcationContext method
 */
public class WLRequestOptions {
	
	private Map<String, String> parameters = new HashMap<String, String>();
	private int timeout = 10000;
	private Object invocationContext;
	private WLResponseListener responseListener;
	
	public int getTimeout() {
		return timeout;
	}
	
	/**
	 * Set the request timeout
	 * @param timeout
	 */
	public void setTimeout(int timeout)   {
		this.timeout = timeout;
	}

	/**
	 * Return the user invocation context
	 * @return
	 */
	public Object getInvocationContext() {
		return invocationContext;
	}

	/**
	 * User can add to the request any object, 
	 * that will be available on the callback (succes/failure) functions.
	 * @param invocationContext
	 */
	public void setInvocationContext(Object invocationContext) {
		this.invocationContext = invocationContext;
	}

	public Map<String, String> getParameters() {
		return parameters;
	}

	protected WLResponseListener getResponseListener() {
		return responseListener;
	}

	protected void setResponseListener(WLResponseListener responseListener) {
		this.responseListener = responseListener;
	}
		
	protected void addParameters(Map<String, String> parameters) {
		this.parameters.putAll(parameters);
	}
	
	protected void addParameter(String name, String value) {
		parameters.put(name, value);
	}
	
	protected String getParameter(String name) {
		return (parameters != null) ? parameters.get(name) : "";
	}
}
